package com.atguigu.lease.web.admin.service.impl;

import com.atguigu.lease.model.entity.FacilityInfo;
import com.atguigu.lease.web.admin.mapper.FacilityInfoMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atguigu.lease.model.entity.ApartmentFacility;
import com.atguigu.lease.web.admin.service.ApartmentFacilityService;
import com.atguigu.lease.web.admin.mapper.ApartmentFacilityMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
* @author liubo
* @description 针对表【apartment_facility(公寓&配套关联表)】的数据库操作Service实现
* @createDate 2023-07-24 15:48:00
*/
@Service
public class ApartmentFacilityServiceImpl extends ServiceImpl<ApartmentFacilityMapper, ApartmentFacility>
    implements ApartmentFacilityService{

    @Autowired
    private FacilityInfoMapper facilityInfoMapper ;

    @Override
    public List<FacilityInfo> getApartmentFacilityListByApartmentId(Long apartmentId) {

        List<ApartmentFacility> apartmentFacilityList = super.list(new LambdaQueryWrapper<ApartmentFacility>().eq(ApartmentFacility::getApartmentId, apartmentId));
        if(apartmentFacilityList==null || apartmentFacilityList.size()<=0){
            return null ;
        }
        List<FacilityInfo> facilityInfoList = facilityInfoMapper.selectList(new LambdaQueryWrapper<FacilityInfo>().in(FacilityInfo::getId, apartmentFacilityList.stream().map(ApartmentFacility::getFacilityId).collect(Collectors.toList())));
        return facilityInfoList;

        //return facilityInfoMapper.getFacilityInfoListByApartmentId(apartmentId);
    }
}




